home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / plaf / basic / BasicSplitPaneDivider.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  5.1 KB  |  155 lines

  1. package javax.swing.plaf.basic;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Cursor;
  6. import java.awt.Dimension;
  7. import java.awt.Graphics;
  8. import java.beans.PropertyChangeEvent;
  9. import java.beans.PropertyChangeListener;
  10. import java.util.EventObject;
  11. import javax.swing.AbstractButton;
  12. import javax.swing.JButton;
  13. import javax.swing.JSplitPane;
  14. import javax.swing.UIManager;
  15.  
  16. public class BasicSplitPaneDivider extends Container implements PropertyChangeListener {
  17.    protected static final int ONE_TOUCH_SIZE = 6;
  18.    protected static final int ONE_TOUCH_OFFSET = 2;
  19.    protected DragController dragger;
  20.    protected BasicSplitPaneUI splitPaneUI;
  21.    protected int dividerSize = 0;
  22.    protected Component hiddenDivider;
  23.    protected JSplitPane splitPane;
  24.    protected MouseHandler mouseHandler;
  25.    protected int orientation;
  26.    protected JButton leftButton;
  27.    protected JButton rightButton;
  28.    static final Cursor horizontalCursor = Cursor.getPredefinedCursor(11);
  29.    static final Cursor verticalCursor = Cursor.getPredefinedCursor(9);
  30.    static final Cursor defaultCursor = Cursor.getPredefinedCursor(0);
  31.  
  32.    public BasicSplitPaneDivider(BasicSplitPaneUI var1) {
  33.       ((Container)this).setLayout(new DividerLayout(this));
  34.       this.setBasicSplitPaneUI(var1);
  35.       this.orientation = this.splitPane.getOrientation();
  36.       ((Component)this).setBackground(UIManager.getColor("SplitPane.background"));
  37.    }
  38.  
  39.    protected JButton createLeftOneTouchButton() {
  40.       1 var1 = new 1(this);
  41.       ((AbstractButton)var1).setFocusPainted(false);
  42.       ((AbstractButton)var1).setBorderPainted(false);
  43.       return var1;
  44.    }
  45.  
  46.    protected JButton createRightOneTouchButton() {
  47.       2 var1 = new 2(this);
  48.       ((AbstractButton)var1).setFocusPainted(false);
  49.       ((AbstractButton)var1).setBorderPainted(false);
  50.       return var1;
  51.    }
  52.  
  53.    protected void dragDividerTo(int var1) {
  54.       this.splitPaneUI.dragDividerTo(var1);
  55.    }
  56.  
  57.    protected void finishDraggingTo(int var1) {
  58.       this.splitPaneUI.finishDraggingTo(var1);
  59.    }
  60.  
  61.    public BasicSplitPaneUI getBasicSplitPaneUI() {
  62.       return this.splitPaneUI;
  63.    }
  64.  
  65.    public int getDividerSize() {
  66.       return this.dividerSize;
  67.    }
  68.  
  69.    public Dimension getPreferredSize() {
  70.       return new Dimension(this.getDividerSize(), this.getDividerSize());
  71.    }
  72.  
  73.    protected void oneTouchExpandableChanged() {
  74.       if (this.splitPane.isOneTouchExpandable() && this.leftButton == null && this.rightButton == null) {
  75.          this.leftButton = this.createLeftOneTouchButton();
  76.          if (this.leftButton != null) {
  77.             this.leftButton.addActionListener(new LeftActionListener(this));
  78.          }
  79.  
  80.          this.rightButton = this.createRightOneTouchButton();
  81.          if (this.rightButton != null) {
  82.             this.rightButton.addActionListener(new RightActionListener(this));
  83.          }
  84.  
  85.          if (this.leftButton != null && this.rightButton != null) {
  86.             ((Container)this).add(this.leftButton);
  87.             ((Container)this).add(this.rightButton);
  88.          }
  89.       }
  90.  
  91.       ((Container)this).invalidate();
  92.       ((Container)this).validate();
  93.    }
  94.  
  95.    public void paint(Graphics var1) {
  96.       super.paint(var1);
  97.    }
  98.  
  99.    protected void prepareForDragging() {
  100.       this.splitPaneUI.startDragging();
  101.    }
  102.  
  103.    public void propertyChange(PropertyChangeEvent var1) {
  104.       if (((EventObject)var1).getSource() == this.splitPane) {
  105.          if (var1.getPropertyName().equals("orientation")) {
  106.             this.orientation = this.splitPane.getOrientation();
  107.             ((Container)this).invalidate();
  108.             ((Container)this).validate();
  109.          } else if (var1.getPropertyName().equals("oneTouchExpandable")) {
  110.             this.oneTouchExpandableChanged();
  111.          }
  112.       }
  113.  
  114.    }
  115.  
  116.    public void setBasicSplitPaneUI(BasicSplitPaneUI var1) {
  117.       if (this.splitPane != null) {
  118.          this.splitPane.removePropertyChangeListener(this);
  119.          if (this.mouseHandler != null) {
  120.             this.splitPane.removeMouseListener(this.mouseHandler);
  121.             this.splitPane.removeMouseMotionListener(this.mouseHandler);
  122.             ((Component)this).removeMouseListener(this.mouseHandler);
  123.             ((Component)this).removeMouseMotionListener(this.mouseHandler);
  124.             this.mouseHandler = null;
  125.          }
  126.       }
  127.  
  128.       this.splitPaneUI = var1;
  129.       if (var1 != null) {
  130.          this.splitPane = var1.getSplitPane();
  131.          if (this.splitPane != null) {
  132.             if (this.mouseHandler == null) {
  133.                this.mouseHandler = new MouseHandler(this);
  134.             }
  135.  
  136.             this.splitPane.addMouseListener(this.mouseHandler);
  137.             this.splitPane.addMouseMotionListener(this.mouseHandler);
  138.             ((Component)this).addMouseListener(this.mouseHandler);
  139.             ((Component)this).addMouseMotionListener(this.mouseHandler);
  140.             this.splitPane.addPropertyChangeListener(this);
  141.             if (this.splitPane.isOneTouchExpandable()) {
  142.                this.oneTouchExpandableChanged();
  143.             }
  144.          }
  145.       } else {
  146.          this.splitPane = null;
  147.       }
  148.  
  149.    }
  150.  
  151.    public void setDividerSize(int var1) {
  152.       this.dividerSize = var1;
  153.    }
  154. }
  155.